package com.wl.designpattern.iterator;

/**
 * Created by wangliang on 2021/2/23.
 */
public class DeliveryIterator implements Iterator {
    private Aggregate aggregate; //容器对象
    private int index; //当前索引

    public DeliveryIterator(Aggregate aggregate) {
        this.aggregate = aggregate;
    }

    @Override
    public boolean hasNext() {
        if(index < aggregate.size()) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public Object next() {
        return aggregate.get(index++);
    }
}
